package com.wxh.multithread;

/**
 * @ClassName: TestSleepThread
 * @Description: 测试休眠线程
 * @Author wxh
 * @Date: 2021/12/30 10:53
 * @Version V1.0.0
 * @Since 1.8
 */
public class TestSleepThread implements Runnable {


    public static void main(String[] args) {
        TestSleepThread testSleepThread = new TestSleepThread();
        new Thread(testSleepThread,"小明").start();
        new Thread(testSleepThread,"小红").start();
        new Thread(testSleepThread,"黄牛党").start();
    }

    private int ticketNums = 10;

    @Override
    public void run() {
        while (true) {
            if(ticketNums <= 0){
                break;
            }
            // 模拟网络延时：放大问题的发生性--> 线程不安全，数据会出错
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "->拿到了第" + ticketNums-- + "票");
        }
    }

}
